package com.wecheir.service.impl;

import com.wecheir.dao.RoleDao;
import com.wecheir.entity.Role;
import com.wecheir.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;


@Service
@Transactional(rollbackFor = Exception.class)
public class RoleServiceImpl implements RoleService {

    @Resource
    RoleDao roleDao;


    @Override
    public Map<String, Object> getRoleList(int start, Integer limit) {
        Map<String ,Object> data = new HashMap<>();
        List<Role> roleList = roleDao.getRoleList(start,limit);
        Integer count = roleDao.getAllCount();
        data.put("roleList",roleList);
        data.put("count",count);
        return data;
    }



    @Override
    public Boolean delRoleById(String id) {
        return roleDao.delRoleById(id);
    }

    @Override
    public void delRolesById(String[] ids) {
        roleDao.delRolesById(ids);
    }

    @Override
    public void addRole(Role role, String byUid) {
        String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        role.setCreateDate(new Date());
        role.setUpdateDate(new Date());
        role.setId(uuid);
        roleDao.addRole(role,byUid);
    }
}
